package com.example.chapter12;


import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/*
*12.2.1.流的概念与创建
* */
public class Demo01 {

    public static void main(String[] args) {
        List<String> list = Arrays.asList("a", "b", "c");
        Stream<String> stream = list.stream(); // 从List创建流

        int[] array1 = {1, 2, 3, 4, 5};
        IntStream intStream = Arrays.stream(array1); // 从int数组创建IntStream对于对象数组，你可以使用Stream.of()方法：
        String[] array = {"a", "b", "c"};
        Stream<String> stream1 = Stream.of(array); // 从对象数组创建Stream


        Stream<String> emptyStream = Stream.empty(); // 创建一个空的流
        Stream<String> stringStream = Stream.of("Hello", "World"); // 创建一个包含特定元素的流

        try (Stream<String> lines = Files.lines(Paths.get("path/to/file.txt"))) {
            lines.forEach(System.out::println); // 处理文件中的每一行
        } catch (IOException e) {
            e.printStackTrace();
        }


        Random random = new Random();
        IntStream randomInts = random.ints(10, 0, 100); // 生成10个0到99之间的随机整数流

        Stream<Integer> infiniteStream = Stream.iterate(0, n -> n + 1); // 创建一个从0开始的无限递增整数流

    }

}
